package com.yeeverse.sdk.vo;

import com.alibaba.fastjson.JSON;
import com.yeeverse.sdk.api.SdkContext;
import com.yeeverse.sdk.util.AES128CBC;
import com.yeeverse.sdk.util.RSAUtils;
import com.yeeverse.sdk.vo.api.BaseRequest;

import java.util.Map;

public class ReqHeadDataVO {

    private String appid;

    private String sign;

    private String aesKey;

    public ReqHeadDataVO(BaseRequest request) {
        //获取当前appid
        this.appid = SdkContext.getCurrentSdk().getAppId();
        //获取当前aes密钥
        this.aesKey = SdkContext.getCurrentSdk().getAesKey();
        //对业务请求报文加签
        try {
            String requestStr = JSON.toJSONString(request);
            this.sign = RSAUtils.sign(requestStr.getBytes(), SdkContext.getCurrentSdk().getPrivateKey());
        } catch (Exception e) {
            throw new RuntimeException("请求头信息生成签名异常", e);
        }
    }

    public ReqHeadDataVO(Map<String, Object> request) {
        //获取当前appid
        this.appid = SdkContext.getCurrentSdk().getAppId();
        //获取当前aes密钥
        this.aesKey = SdkContext.getCurrentSdk().getAesKey();
        //对业务请求报文加签
        try {
            String requestStr = JSON.toJSONString(request);
            this.sign = RSAUtils.sign(requestStr.getBytes(), SdkContext.getCurrentSdk().getPrivateKey());
        } catch (Exception e) {
            throw new RuntimeException("请求头信息生成签名异常", e);
        }
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public String getAesKey() {
        return aesKey;
    }

    public void setAesKey(String aesKey) {
        this.aesKey = aesKey;
    }
}
